import { Item } from "../../shared/face/index";
import { BaseBody } from '../../core/rpg';
import { BagFuncResult } from './types';
import sdk from "../../core";
import { ComType } from "../../core/tool/component";
import bag_component from "../../component/bag_component";
import { Bag } from "../../core/bag";

/**
 * BlindBox 功能
 * @param useItem 使用的物品
 * @param useCount 使用数量
 * @param funcData 函数数据
 * @param player 玩家对象
 * @returns 使用结果
 */
export async function BlindBox(useItem: Item, useCount: number, funcData: any, player: BaseBody): Promise<BagFuncResult> {
    try {
        let com_bag = player.getComponent(ComType.背包) as bag_component;
        // TODO: 实现具体逻辑
        let _bag = new Bag();
        let list: Item[] = sdk.prop.coverBoxGift(funcData, useCount);
        list.forEach((item: Item) => {
            _bag.addItem(item);
        });
        com_bag.addBag(_bag);
        let card = sdk.tool.card.create();
        card.title('🎉盲盒奖励');
        card.l('🎉开启盲盒获得以下物品');
        card.merge(_bag.getCard());
        player.client_text(card.getText());
        return {
            success: true,
            message: '功能执行成功',
            data: { action: 'BlindBox' }
        };
    } catch (error: any) {
        return {
            success: false,
            message: '功能执行失败',
            data: { error: error.message }
        };
    }
}
